﻿using M_Manufacture.API.Application.Command.WorkOrderCommand;
using M_Manufacture.Repository.Interface;
using MediatR;

namespace M_Manufacture.API.Application.CommandHandlers.WorkOrderCommandHandler
{
    /// <summary>
    /// 暂停工单
    /// </summary>
    public class ZhantTingWorkOrderCommandHandler : IRequestHandler<ZhantTingWorkOrderCommand, int>
    {
        private readonly IWorkOrderRepository _workOrderRepository;
        public ZhantTingWorkOrderCommandHandler(IWorkOrderRepository workOrderRepository)
        {
            _workOrderRepository = workOrderRepository;
        }
        public async Task<int> Handle(ZhantTingWorkOrderCommand request, CancellationToken cancellationToken)
        {
            var ss = await _workOrderRepository.GetModelsAsync(request.WorkOrderId);
            if (request.WorkOrderSart == "已暂停")
            {
                ss.WorkOrderSart = request.WorkOrderSart;
            }
            if(request.WorkOrderSart == "已关闭")
            {
                ss.WorkOrderSart = request.WorkOrderSart;
            }
            return await _workOrderRepository.UpdateAsync(ss);
        }
    }
}
